package com.hmkj.quote.job;

import com.hmkj.common.baseMapper.GenericPo;
import com.hmkj.core.po.amount.Cash;
import com.hmkj.core.service.amount.CashService;
import com.hmkj.core.service.cache.RedisService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 提现处理定时器
 *
 * @author Vector
 * @create 2017-09-20 14:39
 */
@Slf4j
@Component
public class CashJob {
    @Resource
    private CashService cashService;
    @Resource
    private RedisService redisService;

    /**
     * 定时查询提现结果
     */
    @Scheduled(fixedDelay = 1000 * 60 * 30)// 上次任务执行完后隔30分钟再执行
    public void payExpiredTender() {
        List<Cash> list = cashService.select(new Cash(t -> {
            t.setStatus(Cash.STATUS.T3.code);
            t.setDelFlag(GenericPo.DELFLAG.NORMAL.code);
        }));
        if (CollectionUtils.isNotEmpty(list)) {
            for (Cash cash : list) {
                try {
//                    // 查询连连代付订单状态
//                    cashService.queryOrderByLianLian(cash);
                    // 查询华融代付订单状态
                    cashService.queryOrderByHR(cash);
                } catch (Exception e) {
                    log.error("提现查询结果定时器处理失败：提现ID：" + cash.getId() + ",信息：" + e.getMessage());
                    e.printStackTrace();
                }
            }
        }
    }
}
